import {
  Body,
  ClassSerializerInterceptor,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Post,
  UseGuards,
  UseInterceptors,
} from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
import { RolesGuard } from 'src/auth/guards/roles.guard';
import { Id } from '../live/dto/id';
import { AllMovieDto } from './dto/all-movie';
import { CreateMovieDto } from './dto/create-movie';
import { Movie } from './entities/movies.entity';
import { MoviesService } from './movies.service';

@ApiTags('房内列表')
@ApiBearerAuth()
@Controller('movies')
export class MoviesController {
  constructor(private readonly movieService: MoviesService) {}

  @ApiBody({ type: CreateMovieDto })
  @ApiResponse({ type: Movie })
  @UseInterceptors(ClassSerializerInterceptor)
  @Post('create')
  async create(@Body() createMovie: CreateMovieDto) {
    return await this.movieService.create(createMovie);
  }

  @ApiResponse({ type: [Movie] })
  // @UseGuards(RolesGuard)
  @UseInterceptors(ClassSerializerInterceptor)
  @Post('all')
  async findAll(@Body() live: AllMovieDto) {
    // console.log(liveId);
    return this.movieService.findAll(live.liveId);
  }

  @Delete(':id')
  async remove(@Param('id', ParseIntPipe) id: string) {
    return this.movieService.remove(id);
  }

  @ApiBody({ type: Id })
  @Post('delete')
  async deleteAt(@Body() id: Id) {
    return await this.movieService.remove(id.id);
  }
}
